<?php
namespace app\index\controller;

use think\Controller;
use app\index\validate\Dologin;
use app\index\model\User;

class Login extends controller
{
    public function login()
    {
        $inputText = file_get_contents("php://input");
        $inputData = json_decode($inputText,true);

        $username = $inputData["name"];
        $password = $inputData["password"];


        $validate = new Dologin();
        if(!$validate->check($inputData)){
            $hint=$validate->getError();
            $retData = [
                "status"=>"fail",
                "message" => $hint
            ];
        }else{
            $UserModel = new User();
            $user = $UserModel->checkUser($username,$password);
            if(is_array($user)){
                $retData = [
                    "status"=>"success",
                    "message" =>"success",
                    "userstatus"=>$user["userstatus"],
                    "Id"=>$user["Id"],
                    "userName"=>$user["userName"]
                ];
            }else{
                $hint = $user;
                $retData = [
                    "status"=>"fail",
                    "message" => $hint
                ];
            }
        }

        die(json_encode($retData));
        return $retData;
    }
}
